package cn.circle.system.service.impl;

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.circle.system.dao.ISysCustomerDao;
import cn.circle.system.dao.ISysLostAndFoundDao;
import com.graduation.system.model.SysCustomer;
import com.graduation.system.model.SysLostAndFound;


import cn.circle.system.service.ISysLostAndFoundService;
import cn.circle.system.util.DataGrid;
import cn.circle.system.util.HqlHelper;
import cn.circle.system.util.PageHelper;

/**
 * 实现SysCustomer接口方法 
 * 作者：
 * 日期：2016/9/13
 **/


@Service
public class SysLostAndFoundServerImpl implements ISysLostAndFoundService{
	
		@Autowired
		private ISysLostAndFoundDao sysLostAndFoundDao;
		
		public DataGrid datagrid(PageHelper ph, SysLostAndFound sysLostAndFound ,String depId, String arcitleName) {
			DataGrid dg = new DataGrid();
			
			
			List<SysLostAndFound> cml = new ArrayList<SysLostAndFound>();
			// 用来放置查询的条件
			Map<String, Object> params = new HashMap<String, Object>();
			// 注意下面为HQL语句，里面sql的关键字大小写不敏感，其它是敏感的,from后面是model类名称
			StringBuffer hql = new StringBuffer("from SysLostAndFound t where 1=1 ");
			// 以下为查询条件
			if (null != depId && Integer.parseInt(depId) != 0) {
				System.out.println(depId);
				params.put("depId", Integer.parseInt(depId));
				hql.append(" and t.sysDepartment.depId = :depId ");
			}
			if (arcitleName != null && !"".equals(arcitleName)) {
				System.out.println(arcitleName);
				String custName = null;
				try {
					custName = URLDecoder.decode(sysLostAndFound.getArcitleName(), "GBK");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				params.put("arcitleName", "%" + custName + "%");
				hql.append(" and t.arcitleName like :arcitleName ");
			}
			hql = HqlHelper.orderHql(hql, ph); // 排序
			List<SysLostAndFound> l = sysLostAndFoundDao.find(hql.toString(), params, ph.getPage(), ph.getRows());
			
			dg.setRows(l);//
			dg.setTotal((long)l.size());
			return dg;
		}
	   
		public boolean save(SysLostAndFound sysLostAndFound) {
		//	SessionFactory sessionFactory 
		   sysLostAndFoundDao.save(sysLostAndFound);
			return true;
		}
	   
		public List<SysLostAndFound> getUser(String id) {
			String hql = "from SysLostAndFound s where s.arcitleId="+id;
			List<SysLostAndFound> c = sysLostAndFoundDao.find(hql);
			return c;
		}
		
		public boolean update(SysLostAndFound sysLostAndFound) {
			sysLostAndFoundDao.updateAll(sysLostAndFound);
			return false;
		}
		
		public boolean deleteAll(String ids) {
			// TODO Auto-generated method stub
			sysLostAndFoundDao.deleteAll(ids);
			return false;
		}
		public boolean removeAll(String ids) {
			// TODO Auto-generated method stub
			sysLostAndFoundDao.removeAll(ids);
			return false;
		}
	
}

	
	